<template>
	<view class="wap">
		<navbar :parameter='parameter'></navbar>
		<view class="box acea-row row-middle" v-if="free.length > 1">
			<text class="iconfont icon-liebiaodaohang_gongyi"></text>{{month}}公益陪诊日 <text
				class="free-day">{{freeDay}}</text>
		</view>
		<navigator class="box acea-row row-between-wrapper" url="/pages/accompanying/public_schedule"
			v-else-if="free.length == 1">
			<view class="acea-row row-middle">
				<text class="iconfont icon-liebiaodaohang_gongyi"></text>请前往设置{{tabList[1]}}公益陪诊日
			</view>
			<text class="iconfont icon-icon_xiangyou"></text>
		</navigator>
		<navigator class="box acea-row row-between-wrapper" url="/pages/accompanying/public_schedule" v-else>
			<view class="acea-row row-middle">
				<text class="iconfont icon-liebiaodaohang_gongyi"></text>公益陪诊日暂未设置,请前往设置
			</view>
			<text class="iconfont icon-icon_xiangyou"></text>
		</navigator>
		<u-calendar :maxDate="maxDate" :defaultDate="defaultDateMultiple" mode="multiple" color="#347DFE"
			confirmText="提交" @confirm="confirm" @scroll="scroll" ref="calendar">
		</u-calendar>
		<view class="cont2">注：日历可上下滚动查看</view>
		<view class="box acea-row row-between-wrapper">
			<view class="acea-row row-middle">
				<view class="acea-row row-middle part"> <text class="yuan"></text> 陪诊日 </view>
				<view class="acea-row row-middle part"> <text class="dian"></text>未选 休息日 </view>
			</view>
			<!-- 	<view class="acea-row row-middle" @click="checkedTap()">
				<radio :checked="active" color='#347DFE' /> 选择全部日期
			</view> -->
		</view>
		<view class="cont-box">
			<u-parse :content="content"></u-parse>
		</view>


		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	const d = new Date()
	const year = d.getFullYear()
	let month1 = d.getMonth() + 1;
	let month2 = d.getMonth() + 2;
	let tabList = [`${month1}月`, `${month2}月`]
	month1 = month1 < 10 ? `0${month1}` : month1;
	const date = d.getDate()
	export default {

		data() {
			return {
				parameter: {
					'navbar': '1',
					'return': '1',
					'title': '日程管理',
					'color': true,
					'class': 'on'
				},
				maxDate: `${year}-${month1}-${date + 29}`,
				defaultDateMultiple: [],
				free: [],
				freeDay: '',
				month: '',
				active: '',
				tabList: tabList,
				scheduleDay: [],
				content: ''
			};

		},
		onLoad(option) {
			var a = this.isBlank(option.free)
			// var b = this.isBlank(option.schedule)
			// console.log(b);
			if (!a) {
				this.free = JSON.parse(option.free)

				console.log(this.free)
			}
			// if (!b) {
			// 	var scheduleDay = JSON.parse(option.schedule)				
			// 	console.log(option.schedule)
			// 	if(scheduleDay.length <= 2){
			// 		this.getAllDay()	
			// 	}else{
			// 		this.scheduleDay = scheduleDay
			// 		this.defaultDateMultiple = scheduleDay
			// 	}
			// } else {
			// 	console.log('空');
			// 	this.getAllDay()				
			// }
			this.getAllDay();
			this.getTasks();
		},
		onShow() {

		},

		methods: {
			confirm(e) {
				console.log(e);
				this.schedule(e)
			},
			getAllDay() {
				var dateList = [];
				let startDate = new Date();
				let endDate = new Date();
				endDate.setDate(startDate.getDate() + 29);
				console.log(startDate);
				while ((endDate.getTime() - startDate.getTime()) >= 0) {
					let month = (startDate.getMonth() + 1).toString().length === 1 ? "0" + (startDate.getMonth() + 1)
						.toString() : (
							startDate.getMonth() + 1);
					let day = startDate.getDate().toString().length === 1 ? "0" + startDate.getDate() : startDate
						.getDate();
					let year = startDate.getFullYear()
					dateList.push(year + "-" + month + "-" + day);
					startDate.setDate(startDate.getDate() + 1);
				}
				this.defaultDateMultiple = dateList;
				this.$refs.calendar.all(this.defaultDateMultiple)
			},
			scroll(e) {
				var free = this.free;
				console.log(e);
				this.freeDay = free[e];
				this.month = tabList[e];
			},
			// 判断是否为空 返回true/false
			isBlank(data) {
				if (
					data == null ||
					data === 'null' ||
					data === '' ||
					data === undefined ||
					data === 'undefined' ||
					data === 'unknown' ||
					data === '[]'
				) {
					return true
				} else {
					return false
				}
			},
			// checkedTap() {
			// 	if (this.active) { // 如果已经选中，则取消选中
			// 		this.active = false;
			// 		// this.defaultDateMultiple = this.scheduleDay

			// 	} else { // 否则进行选中赋值
			// 		this.active = true;
			// 		this.getAllDay()

			// 	}
			// },
			async schedule(date) {
				const res = await this.$myRequest({
					url: '/api/manage/scheduleManage',
					data: {
						openid: uni.getStorageSync('openid'),
						date: date
					}
				})
				if (res.data.status == 200) {
					this.$refs.uToast.show({
						type: 'success',
						message: '提交成功',
						complete() {
							uni.navigateBack()
						}
					})
				}
			},

			async getTasks() {
				const res = await this.$myRequest({
					url: '/api/index/getTasks',
					data: {
						openid: uni.getStorageSync('openid'),
					}
				})
				console.log(res);
				this.content = res.data.data.content;
			},
		},
	}
</script>

<style lang="scss" scoped>
	.wap {
		padding: 20rpx;
	}

	.cont-box {
		font-size: 28rpx;
		padding: 30rpx;
		background-color: #fff;
		line-height: 1.6;
	}	

	.cont2 {
		font-size: 24rpx;
		line-height: 1.8;
		padding: 30rpx;
	}

	.box {
		padding: 0 30rpx;
		background-color: #fff;
		height: 100rpx;
		margin-bottom: 30rpx;
		font-size: 28rpx;
	}

	.box .icon-liebiaodaohang_gongyi {
		font-size: 42rpx;
		color: #00BA53;
		margin-right: 10rpx;
		margin-top: 6rpx;
	}

	.part {
		margin-right: 30rpx;
	}

	.part text {
		margin-right: 6rpx;
	}

	.part .yuan {
		width: 30rpx;
		height: 10rpx;
		border-radius: 10rpx;
		background-color: #347DFE;
	}

	.part .dian {
		width: 10rpx;
		height: 10rpx;
		border-radius: 10rpx;
		background-color: #ccc;
	}

	.free-day {
		color: #347DFE;
		font-weight: 700;
	}
</style>
